package com.zhs.demoutil.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhs.demoutil.dao.BaseCheckResultDao;
import com.zhs.demoutil.dao.CheckResultProDao;
import com.zhs.demoutil.entity.BaseCheckResult;
import com.zhs.demoutil.entity.CheckResultPro;
import com.zhs.demoutil.entity.TmpCheckResult;
import com.zhs.demoutil.service.BaseCheckResultService;
import com.zhs.demoutil.service.CheckResultProService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service
public class CheckResultProServiceImpl extends ServiceImpl<CheckResultProDao, CheckResultPro> implements CheckResultProService {
    @Override
    public void saveOrUpdateBatchByCardNumber(List<CheckResultPro> data) {
        List<String> cardNumberList = data.stream().map(CheckResultPro::getCARDNUMBER).collect(Collectors.toList());
        QueryWrapper<CheckResultPro> checkResultProQueryWrapper = new QueryWrapper<>();
        checkResultProQueryWrapper.in("CARDNUMBER",cardNumberList);
        List<CheckResultPro> list = list(checkResultProQueryWrapper);
        List<String> exitsList = list.stream().map(CheckResultPro::getCARDNUMBER).collect(Collectors.toList());
        List<CheckResultPro> result = data.stream().filter(checkResultPro -> !exitsList.contains(checkResultPro.getCARDNUMBER())).collect(Collectors.toList());
        if(result.size()>0){
            saveBatch(result);
        }
    }
}
